/**
 * Created by wangjian on 2017/10/20.
 * 日历组件
 */
angular.module('app').component('mDatepicker', {
    templateUrl: getTemplateUrl('matrix/component/tpl/mDatepicker.html'),
    bindings: {
        label: '@',
        selectDt:'=',
        onBlur:"&",
        isDisabled:"="
    },
    controller: function ($scope, $element, $attrs, $filter,$timeout) {
        var ctrl = this;
        ctrl.format = 'yyyy-MM-dd';
        ctrl.today = function () {
                ctrl.selectDt = $filter('date')(new Date(), ctrl.format);
        };
        $timeout(function(){
            if (ctrl.selectDt == undefined  || ctrl.selectDt == null) {
                ctrl.today();
            } else {
                ctrl.selectDt = $filter('date')(ctrl.selectDt, ctrl.format);
            }
        },100);

        ctrl.clear = function () {
            ctrl.selectDt = null;
        };

        ctrl.open = function ($event) {
            $event.preventDefault();
            $event.stopPropagation();
            ctrl.opened = true;
        };
        ctrl.dateOptions = {
            formatYear: 'yy',
            startingDay: 1,
            class: 'datepicker',
            showWeeks: false
        };
        ctrl.blurfunction=function(){
            // var type=typeof ctrl.selectDt;
            // console.log(type=='object')
            // if(type=='object'){
            //     ctrl.selectDt=Date.parse(ctrl.selectDt)
            //     console.log(ctrl.selectDt)
            // }
            ctrl.onBlur({
                
            });
        }


       
    }
});
